<template>
  <view>
    <van-tabs :active="activePage" @change="onTabChange" animated>
      <van-tab title="添加代办">
        <add-todo v-if="ready" :todoFromParent="todo" :state="1" @addFinish="addFinish"> </add-todo>
      </van-tab>
      <!-- 添加看板 -->
      <van-tab title="添加看板">
        <van-cell-group>
          <!-- 代办名称 -->
          <van-field
            label="看板名称"
            :value="board_title"
            placeholder="请输入"
            :border="true"
            clearable
            required
            @change="boardTitleChange"
          />
        </van-cell-group>
        <van-row>
          <van-col span="6" offset="9">
            <button
              style="margin-top: 30px"
              type="default"
              @click="submitAddBoard"
            >
              提交
            </button>
          </van-col>
        </van-row>
      </van-tab>
    </van-tabs>
  </view>
</template>

<script>
import { addTodo } from '../addTodo/addTodo';

export default {
  components: { addTodo },
  data() {
    return {
      activePage: 0,
      board_title: '',
      boardList: [],
      boardColumns: [],
      todo: {
        urgent: 2,
        t_time: new Date().getTime(),
        t_desc: null,
        t_title: null,
        t_board: {},
      },
      ready: false,
    };
  },
  methods: {
    async onTabChange(e) {
      console.log(e);
      // 刷新看板栏
      if (e.detail.index == 0) {
        this.ready = true;
      } else {
        this.ready = false;
      }
    },
    // async getBoard() {
    //   const res = await this.hjRequest.run('findBoard');
    //   console.log(res);
    //   this.boardList = [];
    //   this.boardColumns = [];
    //   res.boardList.forEach((item) => {
    //     this.boardList.push({
    //       board_title: item.b_title,
    //       board_id: item._id,
    //     });
    //     this.boardColumns.push(item.b_title);
    //   });
    //   // 默认选中看板的第一个
    //   this.todo.t_board = this.boardList[0];
    // },
    boardTitleChange(e) {
      this.board_title = e.detail;
    },
    addFinish(){
      this.ready=false
      this.$emit("addFinish")
    },
    //添加看板
    async submitAddBoard() {
      wx.showToast({
        title: `上传中...`,
        icon: 'loading',
      });

      const res = await this.hjRequest.run('addBoard', {
        b_title: this.board_title,
      });
      wx.hideToast();
      wx.showToast({
        title: `上传成功`,
        duration: 800,
      });
      console.log(res);
    },
  },
  async created() {
    // await this.getBoard();
    this.ready = true;
  },
};
</script>
<style scoped></style>
